//
//  SNOrderFormFooterView.m
//  app
//
//  Created by 王少宁 on 15/5/11.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "SNOrderFormFooterView.h"

@interface SNOrderFormFooterView ()
@property (nonatomic, retain) UIButton * cancleOrderBtn;
@property (nonatomic, retain) UIButton * chatWithSeverBtn;
@property (nonatomic, retain) UIButton * receiveGoodsBtn;
@end

@implementation SNOrderFormFooterView

- (instancetype)initWithType:(int)type
{
    if ([super init]) {
        
        [self createChatWithServerBtn];
        if (!type) {//含有取消订单
            [self createCancleOrderBtn];
        }
//        else if (type == 1) { //已经付款,可以确认收货
//            [self createReceiveGoodsBtn];
//        }
    }
    return self;
}

- (void)createChatWithServerBtn
{
    _chatWithSeverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _chatWithSeverBtn.frame = CGRectMake(50, 20, SCREEN_WIDTH-100, 40);
    UIImage * btnBackGroundImg = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"btnBackGround@2x" ofType:@"png"]];
    btnBackGroundImg = [btnBackGroundImg resizableImageWithCapInsets:UIEdgeInsetsMake(UP(6), UP(6), UP(6), UP(6)) resizingMode:UIImageResizingModeStretch];
    [_chatWithSeverBtn setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"chatWithSeverPic@2x" ofType:@"png"]] forState:UIControlStateNormal];
    _chatWithSeverBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    _chatWithSeverBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [_chatWithSeverBtn setBackgroundImage:btnBackGroundImg forState:UIControlStateNormal];
    _chatWithSeverBtn.titleLabel.font = JKAppGlobleFontMenu;
    [_chatWithSeverBtn setTitle:kChatWithSeverBtnTitle forState:UIControlStateNormal];
    [_chatWithSeverBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_chatWithSeverBtn];
}

- (void)createCancleOrderBtn
{
    _chatWithSeverBtn.frame = CGRectMake(SCREEN_CENTER.x-20, 20, SCREEN_CENTER.x, 40);
    
    _cancleOrderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _cancleOrderBtn.frame = CGRectMake(20, 20, _chatWithSeverBtn.ufo.x-40, 40);
    UIImage * btnBackGroundImg = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"btnBackGround_gray@2x" ofType:@"png"]];
    btnBackGroundImg = [btnBackGroundImg resizableImageWithCapInsets:UIEdgeInsetsMake(UP(6), UP(6), UP(6), UP(6)) resizingMode:UIImageResizingModeStretch];
    [_cancleOrderBtn setBackgroundImage:btnBackGroundImg forState:UIControlStateNormal];
    _cancleOrderBtn.titleLabel.font = JKAppGlobleFontMenu;
    [_cancleOrderBtn setTitle:kCancleOrderBtnTitle forState:UIControlStateNormal];
    [_cancleOrderBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_cancleOrderBtn];
}

- (void)createReceiveGoodsBtn
{
    _chatWithSeverBtn.frame = CGRectMake(SCREEN_CENTER.x-20, 20, SCREEN_CENTER.x, 40);
    
    _receiveGoodsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _receiveGoodsBtn.frame = CGRectMake(20, 20, _chatWithSeverBtn.ufo.x-40, 40);
    UIImage * btnBackGroundImg = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"btnBackGround_red@2x" ofType:@"png"]];
    btnBackGroundImg = [btnBackGroundImg resizableImageWithCapInsets:UIEdgeInsetsMake(UP(6), UP(6), UP(6), UP(6)) resizingMode:UIImageResizingModeStretch];
    [_receiveGoodsBtn setBackgroundImage:btnBackGroundImg forState:UIControlStateNormal];
    _receiveGoodsBtn.titleLabel.font = JKAppGlobleFontMenu;
    [_receiveGoodsBtn setTitle:kReceiveGoodsBtnTitle forState:UIControlStateNormal];
    [_receiveGoodsBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_receiveGoodsBtn];
}

- (void)btnClick:(UIButton *)btn
{
    if ([self.deletage respondsToSelector:@selector(footViewClickWithBtnTitle:)]) {
        [self.deletage performSelector:@selector(footViewClickWithBtnTitle:) withObject:btn.currentTitle];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
